/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package exercicio.lista2;

import exercicio.util.Distri;
import java.util.Random;

/**
 *
 * @author afonso
 */
public class Questao7 {

    public static void main(String[] args) {
        double normalCDF = Distri.normalCDF(5.0, 7.0, 5.5, 2.2);
        System.out.println("7.1: " + normalCDF);
        System.out.println("7.2: " + (800 * 0.41));

        int nexp = 1000, n = 20;
        double mi = 5.5, desvio = 2.2, soma = 0, mediaAmostra = 0, desv = 0;
        double[] x = new double[20];
        double desv_medio = 0;
        Random r = new Random();

        for (int i = 0; i < nexp; i++) {
            soma = 0.0;

            for (int j = 0; j < 20; j++) {
                x[j] = r.nextGaussian() * desvio + mi;
                soma += x[j];
            }
            mediaAmostra = soma / n;

            for (int j = 0; j < n; j++) {
                desv = desv + Math.pow(x[j] - mediaAmostra, 2);
            }
            desv = Math.sqrt(desv / (n - 1));
            desv_medio += desv;
        }
        desv_medio /= nexp;
        System.out.println("7.3: Desvio da amostra = " + desv_medio);
    }
}
